package main

import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup

func f1(ch chan int) {
	defer wg.Done()
	for i := 0; i < 5; i++ {
		ch <- i
	}
	close(ch)
	for x := range ch {
		fmt.Println(x)
	}
}

func f2() {
	ch1 := make(chan int, 2)
	ch1 <- 10
	ch1 <- 20
	close(ch1)
	/* 	for x := range ch1 {
		fmt.Println(x)
	}*/

	<-ch1
	//<-ch1
	x, ok := <-ch1
	fmt.Println(x, ok)
	x, ok = <-ch1
	fmt.Println(x, ok)
	x, ok = <-ch1
	fmt.Println(x, ok)
}

func main() {
	f2()

	a := make(chan int, 5)
	wg.Add(1)
	go f1(a)
	wg.Wait()
}
